package com.example.dailyrecord.service.impl;

import com.example.dailyrecord.base.entity.SQLBuilder;
import com.example.dailyrecord.base.service.impl.BaseServiceImpl;
import com.example.dailyrecord.entity.Log;
import com.example.dailyrecord.service.LogService;
import com.example.dailyrecord.util.FunctionUtils;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Service
public class LogServiceImpl extends BaseServiceImpl<Log> implements LogService {

    @Override
    public PageInfo<Log> getListRequest(HttpServletRequest request, HttpServletResponse response) {
        String email = getEmail(request);
        startPage(request);
        return PageInfo.of(selectList(SQLBuilder.getInstance().eq(Log.UID_COLUMN, email)));
    }

    @Override
    public void log(HttpServletRequest request, String action, String msg) {
        Log log = Log.getInstance(getEmail(request), action, request.getRequestURI(), FunctionUtils.getIP(request), msg);
        insert(log);
    }
}
